/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.validator;

import com.minierp.bean.EstPriceBean;
import com.minierp.bean.EstPriceMultiBean;
import java.math.BigDecimal;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

public class EstPriceMultiValidator implements Validator {
	public boolean supports(Class clazz) {
		return EstPriceMultiBean.class.isAssignableFrom(clazz);
	}

	public void validate(Object obj, Errors errors) {
		EstPriceMultiBean bean = (EstPriceMultiBean) obj;
		boolean hasError = false;

		for (int i = 0; i < bean.getItems().size(); ++i) {
			EstPriceBean form = (EstPriceBean) bean.getItems().get(i);
			if (!hasError
					&& (form.getEstPrice().getProName() == null || form
							.getEstPrice().getProName().equals(""))
					&& form.getEstPrice().getMakeTypeId() == 0L) {
				errors.rejectValue("items", "", "请选择『项目类型』或输入『材质』");
				hasError = true;
				break;
			}

			if (!hasError && form.getEstPrice().getLength() != null
					&& !form.getEstPrice().getLength().equals("")) {
				try {
					new BigDecimal(form.getEstPrice().getLength());
				} catch (Exception arg9) {
					errors.rejectValue("items", "", "『宽』只能输入数字");
					hasError = true;
					break;
				}
			}

			if (!hasError && form.getEstPrice().getWidth() != null
					&& !form.getEstPrice().getWidth().equals("")) {
				try {
					new BigDecimal(form.getEstPrice().getWidth());
				} catch (Exception arg8) {
					errors.rejectValue("items", "", "『高』只能输入数字");
					hasError = true;
					break;
				}
			}

			if (!hasError && form.getEstPrice().getMakeRequire() != null
					&& form.getEstPrice().getMakeRequire().length() >= 5000) {
				hasError = true;
				errors.rejectValue("items", "", "『制作要求』不能超过5000个字符");
				break;
			}

			if (!hasError) {
				try {
					form.getEstPrice().setPrice(
							new BigDecimal(form.getPriceStr()));
				} catch (Exception arg7) {
					hasError = true;
					errors.rejectValue("items", "", "『单价』只能输入数字");
					break;
				}
			}

			if (!hasError && form.getEstPrice().getMark() != null
					&& form.getEstPrice().getMark().length() >= 100) {
				hasError = true;
				errors.rejectValue("items", "", "『备注』不能超过100个字符");
				break;
			}
		}

	}
}